from pymodbus.client import ModbusTcpClient

client = ModbusTcpClient('127.0.0.1', port=502)
if client.connect():
    print("Connected to Modbus TCP server")
    result = client.read_holding_registers(address=0, count=5, unit=1)
    print(result)
    client.close()
else:
    print("Failed to connect to Modbus TCP server")


